package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.OrdersPoint;
import com.qinggeng.project.system.service.IOrdersPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单配送点Controller
 *
 * @author qinggeng
 * @date 2020-06-17
 */
@RestController
@RequestMapping("/system/orderPoint")
public class OrdersPointController extends BaseController {
    @Autowired
    private IOrdersPointService ordersPointService;

    /**
     * 查询订单配送点列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdersPoint ordersPoint) {
        startPage();
        List<OrdersPoint> list = ordersPointService.selectOrdersPointList(ordersPoint);
        return getDataTable(list);
    }

    /**
     * 导出订单配送点列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:export')")
    @Log(title = "订单配送点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrdersPoint ordersPoint) {
        List<OrdersPoint> list = ordersPointService.selectOrdersPointList(ordersPoint);
        ExcelUtil<OrdersPoint> util = new ExcelUtil<OrdersPoint>(OrdersPoint.class);
        return util.exportExcel(list, "point");
    }

    /**
     * 获取订单配送点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:point:query')")
    @GetMapping(value = "/{ordersPointId}")
    public AjaxResult getInfo(@PathVariable("ordersPointId") Long ordersPointId) {
        return AjaxResult.success(ordersPointService.selectOrdersPointById(ordersPointId));
    }

    /**
     * 通过订单编号 获取订单配送点详情
     */
    @GetMapping("/pointDetil/{orderId}")
    public AjaxResult pointDetil(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(ordersPointService.selectOrdersPointByOrdersId(orderId));
    }


    /**
     * 新增订单配送点
     */
    @PreAuthorize("@ss.hasPermi('system:point:add')")
    @Log(title = "订单配送点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdersPoint ordersPoint) {
        return toAjax(ordersPointService.insertOrdersPoint(ordersPoint));
    }

    /**
     * 修改订单配送点
     */
    @PreAuthorize("@ss.hasPermi('system:point:edit')")
    @Log(title = "订单配送点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdersPoint ordersPoint) {
        return toAjax(ordersPointService.updateOrdersPoint(ordersPoint));
    }

    /**
     * 删除订单配送点
     */
    @PreAuthorize("@ss.hasPermi('system:point:remove')")
    @Log(title = "订单配送点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ordersPointIds}")
    public AjaxResult remove(@PathVariable Long[] ordersPointIds) {
        return toAjax(ordersPointService.deleteOrdersPointByIds(ordersPointIds));
    }
}
